import socket

# 创建 UDP 套接字
udp_server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# 绑定服务器地址和端口
server_address = ('192.168.3.8', 5678)  # 替换为实际的服务器地址和端口
udp_server_socket.bind(server_address)

print("udp server listening...")


# 接收数据
data, client_address = udp_server_socket.recvfrom(1024)
print(f"from {client_address} recved data: {data.decode('utf-8')}")

# 发送响应
response = "Hello, client!"
udp_server_socket.sendto(response.encode('utf-8'), client_address)
print("sent Hello, client! to client")
udp_server_socket.close()